<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Output Filters</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="advanced.features.html" title="Chapter 17. Advanced Features">
<link rel="prev" href="advanced.features.postfilters.html" title="Postfilters">
<link rel="next" href="plugins.html" title="Chapter 18. Extending Smarty With Plugins">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Output Filters</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="advanced.features.postfilters.html">Prev</a> </td>
<th width="60%" align="center">Chapter 17. Advanced Features</th>
<td width="20%" align="right"> <a accesskey="n" href="plugins.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Output Filters">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="advanced.features.outputfilters"></a>Output Filters</h2></div></div></div>
<p>
    When the template is invoked via
    <a class="link" href="api.display.html" title="display()"><code class="varname">display()</code></a> or
    <a class="link" href="api.fetch.html" title="fetch()"><code class="varname">fetch()</code></a>, its output can
    be  sent through one or more output filters. This differs from
    <a class="link" href="advanced.features.postfilters.html" title="Postfilters">
    <code class="varname">postfilters</code></a>
    because postfilters operate on compiled templates before they are saved to
    the disk, whereas output filters operate on the template output when it is
    executed.
   </p>
<p>
    Output filters can be either
    <a class="link" href="api.register.filter.html" title="registerFilter()">registered</a> or loaded
    from the
    <a class="link" href="variable.plugins.dir.html" title="$plugins_dir">plugins directory</a> by using the
    <a class="link" href="api.load.filter.html" title="loadFilter()"><code class="varname">loadFilter()</code></a>
    method or by setting the  <a class="link" href="variable.autoload.filters.html" title="$autoload_filters">
    <em class="parameter"><code>$autoload_filters</code></em></a> variable.
    Smarty will pass the template output as the first argument,
    and expect the function to return the result of the processing.
   </p>
<div class="example">
<a name="id460910"></a><p class="title"><b>Example 17.13. Using a template outputfilter</b></p>
<div class="example-contents"><pre class="programlisting">

&lt;?php
// put this in your application
function protect_email($tpl_output, Smarty_Internal_Template $template)
{
    $tpl_output =
       preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!',
                    '$1%40$2', $tpl_output);
    return $tpl_output;
}

// register the outputfilter
$smarty-&gt;registerFilter("output","protect_email");
$smarty-&gt;display("index.tpl');

// now any occurrence of an email address in the template output will have
// a simple protection against spambots
?&gt;

    </pre></div>
</div>
<br class="example-break"><p>
   See also
   <a class="link" href="api.register.filter.html" title="registerFilter()"><code class="varname">registerFilter()</code></a>,
   <a class="link" href="api.load.filter.html" title="loadFilter()"><code class="varname">loadFilter()</code></a>,
   <a class="link" href="variable.autoload.filters.html" title="$autoload_filters"><em class="parameter"><code>$autoload_filters</code></em></a>,
   <a class="link" href="advanced.features.postfilters.html" title="Postfilters">postfilters</a> and
   <a class="link" href="variable.plugins.dir.html" title="$plugins_dir"><em class="parameter"><code>$plugins_dir</code></em></a>.
   </p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="advanced.features.postfilters.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="advanced.features.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="plugins.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Postfilters </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Chapter 18. Extending Smarty With Plugins</td>
</tr>
</table>
</div>
</body>
</html>
